 //
//  ZCStatusRetweetView.swift
//  weibo
//
//  Created by Ning Xie on 16/8/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit

class ZCStatusRetweetView: UIView {

    var retweetViewConstraint:Constraint?
    var statusViewModel : ZCStatusViewModel? {
        didSet{
            
//            textLabel.text = statusViewModel?.retweetedContent
            textLabel.attributedText = statusViewModel?.retweetAttributedString
            
            retweetViewConstraint?.uninstall()
            if let picUrls = statusViewModel?.status?.retweeted_status?.pic_urls where picUrls.count > 0  {
                picView.hidden = false
                picView.picUrls = picUrls
                
                self.snp_updateConstraints(closure: { (make) in
                    self.retweetViewConstraint = make.bottom.equalTo(picView).offset(StatusTableViewCellMargin).constraint
                })
            }else{
                picView.hidden = true
                self.snp_updateConstraints(closure: { (make) in
                    self.retweetViewConstraint = make.bottom.equalTo(textLabel).offset(StatusTableViewCellMargin).constraint
                })
            }
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //页面布局
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private lazy var textLabel: UILabel = {
        
        let label = UILabel(fontSize: 14, textColor: UIColor.grayColor())
        
        label.numberOfLines = 0
        
        return label
        
    }()
    
    private lazy var picView: ZCStatusPicView = {
        let view = ZCStatusPicView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
    
    //转发微博视图布局
    private func setupUI(){
        
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(textLabel)
        addSubview(picView)
        
        textLabel.text = "好好学习天天向上,先上大学,后搞对象.好好学习天天向上,先上大学,后搞对象.好好学习天天向上,先上大学,后搞对象."
        textLabel.snp_makeConstraints { (make) in
            
            make.top.leading.equalTo(self).offset(StatusTableViewCellMargin)
            make.trailing.equalTo(self).offset(-StatusTableViewCellMargin)
        }
        picView.snp_makeConstraints { (make) in
            make.top.equalTo(textLabel.snp_bottom).offset(StatusTableViewCellMargin)
            make.leading.equalTo(textLabel)
        }
        
        self.snp_makeConstraints { (make) in
            self.retweetViewConstraint = make.bottom.equalTo(picView).offset(StatusTableViewCellMargin).constraint
        }
    }
}
